package com.shareach.http.shop.parameter;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import com.shareach.web.basic.IAskParameter;

public class BizCardParameter implements IAskParameter {
	// 银行
	public String site;
	// 唯一标识
	public String siteFromId;
	// 优惠标题
	public String title;
	// 优惠说明
	public String descry;
	// 截止日期
	public String end;
	// 图片
	public String img;
	// 城市[参见 城市BaseCity]
	public String city;
	// 品牌名称
	public String brandName;
	// 分店名称
	public String name;
	// 采集名
	public String orgName;
	// 采集网址
	public String url;
	// 商家Id[没有绑定为空]
	public Long shopId;
	// 商家电话
	public List<String> tels;
	// 折扣[折扣率*100]
	public Integer discount;
	// 状态
	public Integer status;

	public String addr;

	public Date createTime;

	@Override
	public void parseFromMap(HashMap<String, Object> map) {
		if (map.containsKey("site"))
			this.site = (String) map.get("site");
		if (map.containsKey("name"))
			this.name = (String) map.get("name");
		if (map.containsKey("title"))
			this.title = (String) map.get("title");
		if (map.containsKey("descry"))
			this.descry = (String) map.get("descry");
		if (map.containsKey("end"))
			this.end = (String) map.get("end");
		if (map.containsKey("img"))
			this.img = (String) map.get("img");
		if (map.containsKey("city"))
			this.city = (String) map.get("city");
		if (map.containsKey("discount"))
			this.discount = (Integer) map.get("discount");
		if (map.containsKey("brandName"))
			this.brandName = (String) map.get("brandName");
		if (map.containsKey("orgName"))
			this.orgName = (String) map.get("orgName");
		if (map.containsKey("url"))
			this.url = (String) map.get("url");
		if (map.containsKey("addr"))
			this.addr = (String) map.get("addr");
		if (map.containsKey("tels"))
			this.tels = this.getArrayList(map, "tels");
		if (map.containsKey("shopId"))
			try {
				this.shopId = (Long) map.get("shopId");
			} catch (Exception e) {
				Integer rawInt = (Integer) map.get("shopId");
				this.shopId = (long) rawInt.intValue();
			}
		if (map.containsKey("siteFromId"))
			this.siteFromId = (String) map.get("siteFromId");

		if (map.containsKey("discount"))
			this.discount = (Integer) map.get("discount");
		if (map.containsKey("status"))
			this.status = (Integer) map.get("status");
	}

	@SuppressWarnings("unchecked")
	private <T> ArrayList<T> getArrayList(HashMap<String, Object> map, String field) {
		if (map.containsKey(field)) {
			return (ArrayList<T>) map.get(field);
		} else {
			return null;
		}
	}
}
